#include "sha1sum.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <errno.h>

int main (int argc, char **argv)
{
    assert (sizeof (u32) == 4);
//--------- 
	char a = -20;
	unsigned char b = (unsigned char)a;
	printf("char a is %c ,%d , unsigned char b is %c ,%d \n", a, a, b, b);
//---------
    if (argc < 2)
    {
        fprintf (stderr, "usage: sha1sum filenames\n");
        exit (1);
    }
    for (argc--, argv++; argc; argv++, argc--)
    {
        FILE *fp;
        char buffer[4096];
        size_t n;
        SHA1_CONTEXT ctx;
        int i;
      
        fp = fopen (*argv, "rb");
        if (!fp)
        {
            fprintf (stderr, "can't open `%s': %s\n", *argv, strerror (errno));
            exit (1);
        }
        sha1_init (&ctx);
        while ( (n = fread (buffer, 1, sizeof buffer, fp)))
            sha1_write (&ctx, (unsigned char*)buffer, n);
        if (ferror (fp))
        {
            fprintf (stderr, "error reading `%s': %s\n", *argv,strerror (errno));
            exit (1);
        }
        sha1_final (&ctx);
        fclose (fp);
      
        for (i=0; i < 20; i++)
            printf ("%02x", ctx.buf[i]);
        printf ("  %s\n", *argv);
    }
    return 0;
}

